//
//  FunnyViewController.m
//  Zaker
//
//  Created by 赵磊 on 16/3/8.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "FunnyViewController.h"

@interface FunnyViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *dataArr;

@end

@implementation FunnyViewController

- (void)handleData
{
    NSString *str = [NSString stringWithFormat:@"http://wl.myzaker.com/?_appid=AndroidPhone&_v=6.4.8&_version=6.47&c=columns&city=dalian"];
    [LHAFNetworkTool getUrl:str body:nil response:LHJSON requestHeadFile:nil success:^(NSURLSessionDataTask *task, id resposeObject) {
        NSArray *arr = resposeObject[@"data"][@"columns"];
        self.dataArr = [FunnyModel modelHandlerWithArray:arr];
        [_tableView reloadData];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
}

- (void)createTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 100) style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    _tableView.separatorStyle = 0;
    [_tableView registerClass:[FunnyTableViewCell class] forCellReuseIdentifier:@"cell"];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 1021;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    FunnyModel *model = _dataArr[indexPath.row];
    FunnyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.model = model;
    cell.num = indexPath.row;
    cell.selectionStyle = 0;
    void (^block)() = ^(FunnyInModel *model) {
        FunnyDetailViewController *detail = [[FunnyDetailViewController alloc] init];
        detail.model = model;
        [self.navigationController pushViewController:detail animated:YES];
    };
    cell.block = block;
    return cell;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"玩乐";
    [self handleData];
    [self createTableView];
}

- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    //NSLog(@"%f", scrollView.contentOffset.y);
    NSString *str = [NSString stringWithFormat:@"%f", scrollView.contentOffset.y];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"scrollViiew" object:nil userInfo:@{@"scroll":str}];
    //NSLog(@"___%@", str);
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
